package com.aks.student.career.service;

import com.aks.student.career.dao.GenericDAO;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;

/**
 * User: tr1a6333
 * Date: 25.07.2011
 * Time: 15:27
 */
@Transactional
public class GenericServiceImpl<T, ID extends Serializable> implements GenericService<T, ID> {

    protected GenericDAO<T, ID> genericDao;

    protected Class<T> persistentClass;

    public GenericServiceImpl() {
        this.persistentClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
    }

    public T loadById(ID id) {
        return (T) genericDao.loadById(id);

    }

    public ID save(T obj) {
        return genericDao.save(obj);
    }

    public void update(T obj) {
        genericDao.update(obj);
    }

    public void delete(T obj) {
        genericDao.delete(obj);
    }

    public List<T> findAll(Class persistanceClass) {
        return genericDao.findAll(persistanceClass);
    }

    public T findById(Class persistanceClass, ID id) {
        return genericDao.findById(persistanceClass, id);
    }

}
